package com.dycx.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * 来源类型
 */
@Getter
@AllArgsConstructor
public enum SourceEnum {

    WX_MP(1, "微信公众号"),
    WX_MINI_APP(2, "微信小程序"),
    IOS_APP(3, "苹果APP"),
    ANDROID_APP(4, "安卓APP"),
    SAAS(5, "saas"),
    H5(6, "H5");

    private final Integer code;
    private final String name;

    public static String converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(WX_MP).getName();
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, String>> getList() {
        List<Map<String, String>> list = new ArrayList<>();
        for (SourceEnum item : SourceEnum.values()) {
            Map<String, String> map = new HashMap<>();
            map.put("code", item.getCode().toString());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }

}
